package limpo;

import java.util.ArrayList;
import java.util.List;

import processing.core.PApplet;
import processing.core.PVector;

@SuppressWarnings("serial")
public class CellMain extends PApplet{
	
	private CellColony colony;
	private List<PVector> pointsBeingDrawn;
	private List<PVector> pointsToDraw;
	
	public void setup(){
		size(800,600);
		this.colony = new CellColony(this);
		this.pointsBeingDrawn = new ArrayList<PVector>();
		this.pointsToDraw = new ArrayList<PVector>();
	}
	
	public void draw(){
		background(0);
		if(pointsBeingDrawn != null){
			for (PVector p : pointsBeingDrawn) {
				stroke(255);
				point(p.x, p.y);
			}
		}
		this.colony.draw();
		//System.out.println(this.colony.size());
	}

	@Override
	public void mouseDragged() {
		PVector current = new PVector(mouseX, mouseY);
		if(!contem(current)){
			pointsBeingDrawn.add(current);
		} else {
			System.out.println("Ok");
			for (PVector p : pointsBeingDrawn) {
				pointsToDraw.add(new PVector(p.x, p.y));
			}
			this.colony.addUnit(pointsToDraw);
			pointsBeingDrawn.clear();
			pointsToDraw.clear();
		}
	}
	
	public boolean contem(PVector current){
		boolean contem = false;
		for (PVector point : pointsBeingDrawn) {
			float cX = current.x;
			float cY = current.y;
			float pX = point.x;
			float pY = point.y;
			if(cX == pX && cY == pY){
				contem = true;
			}
		}
		return contem;
	}
	
	@Override
	public void mouseReleased() {
		pointsBeingDrawn.clear();
	}
	public static void main(String[] args) {
		PApplet.main(new String[] { "--bgcolor=#FFFFFF", "limpo.CellMain" });
	}
}
